#ifndef __LAMBDA_H_
#define __LAMBDA_H_

#define lambda(return_type, block, ...)({	\
	    return_type _f(__VA_ARGS__){	\
		return (block);			\
	    }					\
	    &_f;				\
})

/* examples:

int sum(int (*f)(int), int a, int b)
{
    int s = 0;
    int i;
    for (i = a; i <= b; i++)
	s += f(i);
    return s;
}

void foo()
{
    int (*square)(int) = lambda(int, {x*x;}, int x);
    int (*cube)(int) = lambda(int, {x*x*x;}, int x);
    int i;
    square(2);
    
    for (i = 0; i < 10; i++)
        printf("%d: %d %d\n", i, square(i), cube(i));
    int s = sum(square, 1, 5);
    printf("%d\n", s);
    s = sum(cube, 1, 5);
    printf("%d\n", s);
}

 */

#endif
